Options Pattern how to use

65

Options Pattern how to use -

// AppSettingsController.cs
[Route("appsettings")]
public class AppSettingsController : Controller
{
    ...
    protected readonly IOptions<RoundTheCodeSync> _roundTheCodeSyncOptions;
 
    public AppSettingsController(..., IOptions<RoundTheCodeSync> roundTheCodeSyncOptions)
    {
        ...
        _roundTheCodeSyncOptions = roundTheCodeSyncOptions;
    }
 
    ...
 
    [Route("second-way")]
    public IActionResult SecondWay()
    {
        return Content(_roundTheCodeSyncOptions.Value.Title, "text/plain");
    }
}

Comments

Submit
0 Comments